<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网站链接管理 - 控制面板</title>
    <link rel="stylesheet" href="/css/style.css">
    <style>
        .form-control {
            display: block;
            width: 100%;
            padding: 10px 15px;
            font-size: 16px;
            line-height: 1.5;
            color: rgba(200, 230, 255, 0.9);
            background: linear-gradient(145deg, rgba(10, 20, 40, 0.8), rgba(20, 40, 80, 0.8));
            border: 1px solid rgba(100, 150, 200, 0.3);
            border-radius: 8px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2),
                        inset 0 1px 2px rgba(255, 255, 255, 0.1);
            margin-bottom: 15px;
        }
        
        .form-control:focus {
            outline: none;
            border-color: rgba(0, 170, 255, 0.8);
            box-shadow: 0 0 15px rgba(0, 150, 255, 0.3),
                        inset 0 1px 2px rgba(255, 255, 255, 0.2);
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: rgba(200, 230, 255, 0.9);
        }
        
        .weblink-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            margin-bottom: 30px;
            background-color: rgba(30, 30, 30, 0.7);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }
        
        .weblink-table th, .weblink-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(200, 230, 255, 0.9);
        }
        
        .weblink-table th {
            background-color: rgba(20, 40, 80, 0.8);
            font-weight: bold;
            color: rgba(220, 240, 255, 1);
        }
        
        .weblink-table tr:hover {
            background-color: rgba(40, 60, 100, 0.4);
        }
        
        .action-buttons {
            display: flex;
            gap: 8px;
        }
        
        .btn {
            display: inline-block;
            padding: 8px 16px;
            background: linear-gradient(145deg, rgba(0, 120, 210, 0.8), rgba(0, 80, 160, 0.8));
            color: white;
            text-decoration: none;
            border-radius: 8px;
            border: none;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }
        
        .btn:hover {
            background: linear-gradient(145deg, rgba(0, 140, 230, 0.9), rgba(0, 100, 180, 0.9));
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }
        
        .btn-danger {
            background: linear-gradient(145deg, rgba(210, 40, 40, 0.8), rgba(160, 20, 20, 0.8));
        }
        
        .btn-danger:hover {
            background: linear-gradient(145deg, rgba(230, 60, 60, 0.9), rgba(180, 40, 40, 0.9));
        }
        
        .btn-primary {
            background: linear-gradient(145deg, rgba(0, 120, 210, 0.8), rgba(0, 80, 160, 0.8));
        }
        
        .btn-primary:hover {
            background: linear-gradient(145deg, rgba(0, 140, 230, 0.9), rgba(0, 100, 180, 0.9));
        }
        
        .btn-success {
            background: linear-gradient(145deg, rgba(40, 180, 80, 0.8), rgba(30, 150, 60, 0.8));
        }
        
        .btn-success:hover {
            background: linear-gradient(145deg, rgba(50, 200, 100, 0.9), rgba(40, 170, 80, 0.9));
        }
        
        .btn-warning {
            background: linear-gradient(145deg, rgba(240, 140, 0, 0.8), rgba(200, 120, 0, 0.8));
        }
        
        .btn-warning:hover {
            background: linear-gradient(145deg, rgba(255, 160, 0, 0.9), rgba(220, 140, 0, 0.9));
        }
        
        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 8px;
            backdrop-filter: blur(10px);
        }
        
        .alert-success {
            background-color: rgba(40, 180, 80, 0.2);
            color: #2ecc71;
            border: 1px solid rgba(46, 204, 113, 0.3);
        }
        
        .alert-danger {
            background-color: rgba(180, 40, 40, 0.2);
            color: #e74c3c;
            border: 1px solid rgba(231, 76, 60, 0.3);
        }
        
        .search-section {
            margin-bottom: 20px;
            display: flex;
            gap: 15px;
            background-color: rgba(30, 30, 30, 0.7);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }
        
        .search-form {
            display: flex;
            gap: 10px;
            flex: 1;
        }
        
        .empty-message {
            text-align: center;
            padding: 30px;
            color: rgba(200, 230, 255, 0.7);
            background-color: rgba(30, 30, 30, 0.7);
            backdrop-filter: blur(10px);
            border: 1px dashed rgba(100, 150, 200, 0.3);
            border-radius: 10px;
            margin: 20px 0;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }
        
        .add-form {
            margin-top: 20px;
            padding: 20px;
            background-color: rgba(30, 30, 30, 0.7);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            border: 1px solid rgba(100, 150, 200, 0.3);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }
        
        .add-form h2 {
            margin-top: 0;
            margin-bottom: 20px;
            color: rgba(200, 230, 255, 0.9);
            font-size: 18px;
            border-bottom: 1px solid rgba(100, 150, 200, 0.3);
            padding-bottom: 10px;
        }
        
        .search-result {
            background-color: rgba(0, 120, 210, 0.2);
            padding: 10px 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(0, 120, 210, 0.3);
        }
        
        .search-result-text {
            font-weight: bold;
            color: rgba(200, 230, 255, 0.9);
        }
        
        .clear-search {
            padding: 4px 8px;
            font-size: 12px;
            background: linear-gradient(145deg, rgba(80, 120, 160, 0.8), rgba(60, 100, 140, 0.8));
        }
        
        .weblink-table td a {
            color: #2196F3;
            text-decoration: none;
            display: block;
            padding: 8px 12px;
            margin: -12px -15px;
            border-radius: 6px;
            transition: all 0.3s ease;
            position: relative;
            z-index: 1;
            overflow: hidden;
        }
        
        .weblink-table td a:before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(145deg, rgba(33, 150, 243, 0.05), rgba(33, 150, 243, 0.1));
            border-radius: 6px;
            opacity: 0;
            z-index: -1;
            transition: opacity 0.3s ease;
        }
        
        .weblink-table td a:hover {
            color: #64b5f6;
            box-shadow: 0 0 15px rgba(33, 150, 243, 0.3);
            transform: translateY(-2px);
        }
        
        .weblink-table td a:hover:before {
            opacity: 1;
        }
        
        .weblink-table td a:active {
            transform: translateY(1px);
            box-shadow: 0 0 5px rgba(33, 150, 243, 0.2);
        }
        
        .weblink-table td a:after {
            content: '🔗';
            font-size: 14px;
            margin-left: 8px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        .weblink-table td a:hover:after {
            opacity: 1;
        }
        
        .add-form button[type="submit"] {
            padding: 10px 20px;
            background: linear-gradient(145deg, rgba(0, 180, 50, 0.8), rgba(0, 150, 30, 0.8));
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
        
        .add-form button[type="submit"]:hover {
            background: linear-gradient(145deg, rgba(0, 200, 60, 0.9), rgba(0, 170, 40, 0.9));
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }
        
        .add-form button[type="submit"]:active {
            transform: translateY(1px);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
        }
        
        .add-form button[type="submit"]:before {
            content: '+';
            margin-right: 8px;
            font-size: 18px;
            font-weight: bold;
        }
        
        .icon-selector {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 10px;
        }
        
        .icon-option {
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            background: rgba(40, 60, 100, 0.4);
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .icon-option:hover, .icon-option.selected {
            background: rgba(0, 120, 210, 0.4);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
        }
        
        .status-active {
            color: #2ecc71;
            font-weight: bold;
        }
        
        .status-inactive {
            color: #e74c3c;
            font-weight: bold;
        }
        
        .order-input {
            width: 60px;
            text-align: center;
            padding: 5px;
            border-radius: 4px;
            border: 1px solid rgba(100, 150, 200, 0.3);
            background: rgba(20, 40, 80, 0.4);
            color: rgba(200, 230, 255, 0.9);
        }
    </style>
</head>
<body>
    <div class="dashboard-container">
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>控制面板</h2>
            </div>
            <ul class="sidebar-menu">
                <li><a href="/dashboard">主页</a></li>
                <li><a href="/dashboard/profile">个人信息</a></li>
                <li><a href="/dashboard/change-password">修改密码</a></li>
                <li><a href="/dashboard/documents">文档管理</a></li>
                <li><a href="/dashboard/categories">分类管理</a></li>
                <li><a href="/dashboard/link-categories">网站分类</a></li>
                <li class="active"><a href="/dashboard/weblinks">网站链接</a></li>
                <li><a href="/dashboard/users">用户管理</a></li>
                <li><a href="/danmaku-display">弹幕墙</a></li>
                <li><a href="/" target="_blank">访问首页</a></li>
                <li><a href="/logout">退出登录</a></li>
            </ul>
        </div>
        
        <div class="main-content">
            <div class="dashboard-header">
                <div class="dashboard-title">
                    <h1>网站链接管理</h1>
                </div>
                <div>
                    <a href="/dashboard" class="btn">返回仪表板</a>
                </div>
            </div>
            
            <!-- 成功/错误消息 -->
            <div th:if="${successMessage != null}" class="alert alert-success" th:text="${successMessage}"></div>
            <div th:if="${errorMessage != null}" class="alert alert-danger" th:text="${errorMessage}"></div>
            
            <!-- 搜索表单 -->
            <div class="search-section">
                <form action="/dashboard/weblinks/search" method="get" class="search-form">
                    <input type="text" name="title" placeholder="按标题搜索..." class="form-control">
                    <button type="submit" class="btn">搜索</button>
                </form>
                <form action="/dashboard/weblinks/search" method="get" class="search-form">
                    <input type="text" name="url" placeholder="按URL搜索..." class="form-control">
                    <button type="submit" class="btn">搜索</button>
                </form>
            </div>
            
            <!-- 搜索结果提示 -->
            <div th:if="${searchTerm != null}" class="search-result">
                <div class="search-result-text">
                    <span>搜索结果:</span> 
                    <span th:text="${searchTerm}"></span>
                </div>
                <a href="/dashboard/weblinks" class="btn clear-search">清除搜索</a>
            </div>
            
            <!-- 网站链接列表 -->
            <table class="weblink-table">
                <thead>
                    <tr>
                        <th style="width: 5%;">ID</th>
                        <th style="width: 5%;">图标</th>
                        <th style="width: 15%;">标题</th>
                        <th style="width: 25%;">URL</th>
                        <th style="width: 20%;">描述</th>
                        <th style="width: 10%;">排序</th>
                        <th style="width: 10%;">状态</th>
                        <th style="width: 10%;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr th:if="${webLinks != null && !webLinks.empty}" th:each="link : ${webLinks}">
                        <td th:text="${link.id}"></td>
                        <td th:text="${link.icon}" style="font-size: 20px; text-align: center;"></td>
                        <td th:text="${link.title}"></td>
                        <td><a th:href="${link.url}" target="_blank" th:text="${link.url}"></a></td>
                        <td th:text="${link.description}" style="max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"></td>
                        <td>
                            <form th:action="@{/dashboard/weblinks/order/{id}(id=${link.id})}" method="post" style="display: flex; align-items: center;">
                                <input type="number" name="order" th:value="${link.displayOrder}" class="order-input">
                                <button type="submit" class="btn" style="margin-left: 5px; padding: 5px 8px;">保存</button>
                            </form>
                        </td>
                        <td>
                            <span th:if="${link.active}" class="status-active">激活</span>
                            <span th:unless="${link.active}" class="status-inactive">禁用</span>
                        </td>
                        <td>
                            <div class="action-buttons">
                                <a th:href="@{/dashboard/weblinks/edit/{id}(id=${link.id})}" class="btn btn-primary" title="编辑">✏️</a>
                                <a th:href="@{/dashboard/weblinks/toggle/{id}(id=${link.id})}" 
                                   th:class="${link.active ? 'btn btn-warning' : 'btn btn-success'}" 
                                   th:title="${link.active ? '禁用' : '激活'}">
                                    <span th:text="${link.active ? '🔒' : '🔓'}"></span>
                                </a>
                                <a th:href="@{/dashboard/weblinks/delete/{id}(id=${link.id})}" class="btn btn-danger" 
                                   onclick="return confirm('确定要删除这个网站链接吗？')" title="删除">❌</a>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
            
            <!-- 空状态提示 -->
            <div th:if="${webLinks == null || webLinks.empty}" class="empty-message">
                暂无网站链接，请添加新的链接
            </div>
            
            <!-- 添加新网站链接表单 -->
            <div class="add-form">
                <h2>添加新网站链接</h2>
                <form th:action="@{/dashboard/weblinks}" th:object="${webLink}" method="post">
                    <div class="form-group">
                        <label for="title">标题</label>
                        <input type="text" id="title" th:field="*{title}" required placeholder="请输入网站标题" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="url">URL</label>
                        <input type="url" id="url" th:field="*{url}" required placeholder="https://" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="description">描述</label>
                        <textarea id="description" th:field="*{description}" placeholder="请输入网站描述..." class="form-control"></textarea>
                    </div>
                    <div class="form-group">
                        <label for="icon">图标</label>
                        <input type="text" id="icon" th:field="*{icon}" class="form-control" maxlength="2">
                        <div class="icon-selector">
                            <div class="icon-option" data-icon="🔗">🔗</div>
                            <div class="icon-option" data-icon="🌐">🌐</div>
                            <div class="icon-option" data-icon="📱">📱</div>
                            <div class="icon-option" data-icon="💻">💻</div>
                            <div class="icon-option" data-icon="📚">📚</div>
                            <div class="icon-option" data-icon="🎮">🎮</div>
                            <div class="icon-option" data-icon="🎬">🎬</div>
                            <div class="icon-option" data-icon="🎵">🎵</div>
                            <div class="icon-option" data-icon="📝">📝</div>
                            <div class="icon-option" data-icon="📊">📊</div>
                            <div class="icon-option" data-icon="🛒">🛒</div>
                            <div class="icon-option" data-icon="💼">💼</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="displayOrder">显示顺序</label>
                        <input type="number" id="displayOrder" th:field="*{displayOrder}" class="form-control" value="0">
                    </div>
                    <div class="form-group">
                        <label>
                            <input type="checkbox" th:field="*{active}" checked>
                            激活
                        </label>
                    </div>
                    <button type="submit" class="btn">保存网站链接</button>
                </form>
            </div>
        </div>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 图标选择器
            const iconOptions = document.querySelectorAll('.icon-option');
            const iconInput = document.getElementById('icon');
            
            // 初始选中当前图标
            iconOptions.forEach(option => {
                if (option.dataset.icon === iconInput.value) {
                    option.classList.add('selected');
                }
                
                option.addEventListener('click', function() {
                    // 移除所有选中状态
                    iconOptions.forEach(opt => opt.classList.remove('selected'));
                    // 添加当前选中状态
                    this.classList.add('selected');
                    // 设置输入框值
                    iconInput.value = this.dataset.icon;
                });
            });
        });
    </script>
</body>
</html> 